<!DOCTYPE html>
<html lang="zh">

  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>Model Log</title>
    <meta name="keywords" content="index" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="renderer" content="webkit" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="static/i/favicon.png" />
    <link rel="apple-touch-icon-precomposed" href="static/i/app-icon72x72@2x.png" />
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="static/css/amazeui.min.css" />
    <link rel="stylesheet" href="static/css/admin.css" />
    <link rel="stylesheet" href="static/css/app.css" />
    <script src="static/js/echarts.min.js"></script>
  </head>

  <body data-type="index">

    <header class="am-topbar am-topbar-inverse admin-header">
        <div class="am-topbar-brand">
            <a href="/" class="tpl-logo">
                <img src="static/img/logo.png" alt="">
            </a>
        </div>
        <div class="am-icon-list tpl-header-nav-hover-ico am-fl am-margin-right">

        </div>

        <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-success am-show-sm-only" data-am-collapse="{target: '#topbar-collapse'}"><span class="am-sr-only">导航切换</span> <span class="am-icon-bars"></span></button>

        {% if is_login %}
        <div align="right">
            <span style="color: #000000;font-size: 15px;">欢迎</span>&nbsp;<span style="color: #0b6fa2;font-size: 15px;">{{ nick_name }}!</span>&nbsp;&nbsp;&nbsp;
            <button class="am-btn am-btn-secondary" style="margin-right: 50px;" onclick="login()"><span class="am-icon-exchange"></span>切换昵称</button>
        </div>
        {% endif %}

        <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

        </div>
    </header>






    <div class="tpl-page-container tpl-page-header-fixed">
      <div class="tpl-content-wrapper" style="padding-left: 20px;">
        <div class="tpl-content-page-title">项目列表</div>
          <ol class="am-breadcrumb">
                <li><a href="#" class="am-icon-home">首页</a></li>
                <li class="am-active">项目列表</li>
            </ol>
        <div class="tpl-content-scope">
          <div class="tpl-portlet-components">
            <div class="portlet-title">
              <div class="caption font-green bold">
                <span class="am-icon-code"></span>项目列表</div>
            </div>
            <div class="tpl-block">
              <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                  <div class="am-btn-toolbar">
                    <div class="am-btn-group am-btn-group-xs">
                      <button type="button" class="am-btn am-btn-default am-btn-danger" onclick="del()">
                        <span class="am-icon-trash-o"></span>删除</button>
                    </div>
                  </div>
                </div>
              <div class="am-g">
                <div class="am-u-sm-12">
                  <form class="am-form">
                    <table class="am-table am-table-striped am-table-hover table-main">
                      <thead>
                        <tr>
                          <th class="table-check">
                            <input type="checkbox" class="tpl-table-fz-check" /></th>
                          <th class="table-id">ID</th>
                          <th class="table-title">项目</th>
                          <th class="table-type">备注</th>
                          <th class="table-author am-hide-sm-only">创建时间</th>
                          <th class="table-set">操作</th></tr>
                      </thead>
                      <tbody id="tbody">
                      </tbody>
                    </table>

                    <div class="am-g center_msg" style="display: none;">
                      <div class="am-u-sm-3 am-u-sm-centered" style="width: 350px;">赶快开始训练模型吧！</div>
                    </div>

                    <div class="am-g center_login" style="display: none;">
                      <div class="am-u-sm-3 am-u-sm-centered" style="width: 350px;">赶快填写昵称登录吧！<button type="button" class="am-btn am-btn-success" onclick="login()"><i class="am-icon-user-plus"></i>&nbsp;&nbsp;Login</button></div>
                    </div>


                    <div class="am-cf">
                      <div class="am-fr">
                          <ul data-am-widget="pagination" class="am-pagination am-pagination-select">


                              <li class="am-pagination-prev " onclick="back_page()">
                                <a href="#">上一页</a>
                              </li>


                                <li>
                                  <select id="page_select" onchange="change_page()">
                                  </select>
                                </li>


                              <li class="am-pagination-next " onclick="next_page()">
                                <a href="#">下一页</a>
                              </li>

                            </ul>

                      </div>
                    </div>
                    <hr /></form>
                </div>
              </div>
            </div>
            <div class="tpl-alert"></div>
          </div>
        </div>
      </div>
    </div>

        <footer data-am-widget="footer"
          class="am-footer am-footer-default"
           data-am-footer="{  }">
    <div class="am-footer-switch">
      <a id="godesktop" class="am-footer-desktop" target="_blank" href="https://github.com/NLP-LOVE/Model_Log">
          Model Log
      </a>
    </div>
    <div class="am-footer-miscs ">

          <p>由 <a href="https://github.com/NLP-LOVE" title="mantch"
                                                target="_blank">mantch</a>
            提供开源支持</p>
        <p><a href="https://github.com/NLP-LOVE/Model_Log" target="_blank">https://github.com/NLP-LOVE/Model_Log</a></p>
    </div>
  </footer>



    <div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
      <div class="am-modal-dialog">
        <div class="am-modal-hd">消息</div>
        <div class="am-modal-bd alert_bd">

        </div>
        <div class="am-modal-footer">
          <span class="am-modal-btn">确定</span>
        </div>
      </div>
    </div>


    <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
      <div class="am-modal-dialog">
        <div class="am-modal-hd">警告</div>
        <div class="am-modal-bd">
          你，确定要删除这些记录吗？
        </div>
        <div class="am-modal-footer">
          <span class="am-modal-btn" data-am-modal-cancel>取消</span>
          <span class="am-modal-btn" data-am-modal-confirm>确定</span>
        </div>
      </div>
    </div>


      <div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt">
        <div class="am-modal-dialog">
          <div class="am-modal-hd">Login</div>
          <div class="am-modal-bd">
            昵称
            <input type="text" class="am-modal-prompt-input">
          </div>
          <div class="am-modal-footer">
            <span class="am-modal-btn" data-am-modal-cancel>取消</span>
            <span class="am-modal-btn" data-am-modal-confirm>登录</span>
          </div>
        </div>
      </div>


    <a href="http://www.baidu.com" id="detail_id"></a>
    <script src="static/js/jquery.min.js"></script>
    <script src="static/js/amazeui.min.js"></script>
    <script src="static/js/iscroll.js"></script>
    <script src="static/js/app.js"></script>


    <script>

      $(document).ready(function(){
                var browser = navigator.userAgent.toLowerCase();
                var phone = /iphone|ipod|ipad|android|mobile|blackberry|webos|incognito|webmate|bada|nokia|lg|ucweb|skyfire|micromessenger/i
                if(phone.test(browser)) {
                    window.location.href = '/alert';
                }
            })



      function login() {
        $('#my-prompt').modal({
          relatedTarget: this,
          onConfirm: function(e) {

            if (e.data != ''){
              $.ajax({
                  type : "POST",
                  contentType: "application/json;charset=UTF-8",
                  url : "/login",
                  data : JSON.stringify({'nick_name':e.data}),
                  success : function(result) {

                    if (result['is_success']){
                      location.reload();
                    }

                  },
                  error : function(e){
                      console.log(e.status);
                      console.log(e.responseText);
                  }
              });
            }else{
              alert('请填写昵称！')
            }




          },
          onCancel: function(e) {

          }
        })
      }


      {% if is_login %}

              // 自动获取最新数据
      setInterval(function () {

        // 检测是否有新模型开始训练
        $.ajax({
                type : "POST",
                contentType: "application/json;charset=UTF-8",
                data: JSON.stringify({'model_num':{{model_num}}}),
                datatype: 'json',
                url : "/check_new_model",
                success : function(result) {

                  if (result['is_success']) {

                    if (result['is_jump']){
                      window.location.href="/project_detail?project_id=" + result['project_id'].toString();
                    }

                  }else{
                    $(".alert_bd").text(result['msg'])
                    $modal.modal();
                  }

                },
                error : function(e){
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });


      }, 3000);


      //# 查询项目列表
        function find_page(page_num){
            $.ajax({
              type : "GET",
              contentType: "application/json;charset=UTF-8",
              url : "/get_project_list",
              data : {page:page_num},
              success : function(result) {

                  $("#tbody").html('')

                  for (var i=0; i < result.length; i++){
                      item = result[i]

                      remark = item.project_remark
                      if (remark == null){
                          remark = ''
                      }

                      html = "<tr>\n" +
                          "                          <td>\n" +
                          "                            <input type=\"checkbox\" value='" + item.project_id.toString() + "' /></td>\n" +
                          "                          <td>" + item.id + "</td>\n" +
                          "                          <td>\n" +
                          "                            <a href='/project_detail?project_id=" + item.project_id.toString() + "'>" + item.project_name + "</a></td>\n" +
                          "                          <td>" + remark + "</td>\n" +
                          "                          <td class=\"am-hide-sm-only\">" + item.create_time + "</td>\n" +
                          "                          <td>\n" +
                          "                            <div class=\"am-btn-toolbar\">\n" +
                          "                              <div class=\"am-btn-group am-btn-group-xs\">\n" +
                          "                                <a class=\"am-btn am-btn-secondary\" href='/project_detail?project_id=" + item.project_id.toString() + "' style='font-weight: bold;'>\n" +
                          "                                  <span class=\"am-icon-pencil-square-o\"></span>查看</a>\n" +
                          "                                <button class=\"am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only\" type='button' onclick='del_single(" + item.project_id.toString() + ")'>\n" +
                          "                                  <span class=\"am-icon-trash-o\"></span>删除</button>\n" +
                          "                              </div>\n" +
                          "                            </div>\n" +
                          "                          </td>\n" +
                          "                        </tr>"

                      $("#tbody").append(html)

                  }


              },
              error : function(e){
                  console.log(e.status);
                  console.log(e.responseText);
              }
          });
        }



        find_page(1);
        page_num = 0


        // 初始化页码
        $.ajax({
            type : "GET",
            contentType: "application/json;charset=UTF-8",
            url : "/get_page_num",
            success : function(result) {

                page_num = parseInt(result)

                for (var i=1; i <= page_num; i++){

                    html = "<option value='" + i.toString() + "'>" + i + "/" + result + "</option>"
                    $("#page_select").append(html)
                }

                if (page_num == 0){
                  $(".center_msg").css("display", 'block')
                }else if (page_num > 0){
                  $(".center_msg").css("display", 'none')
                }else{
                  $(".center_login").css("display", 'block')
                }

            },
            error : function(e){
                console.log(e.status);
                console.log(e.responseText);
            }
        });




      {% else %}
      $(".center_login").css("display", 'block')
      login()
      {% endif %}








        function ajax_del(json_data) {

          var $modal = $('#my-alert');


          $('#my-confirm').modal({
            relatedTarget: this,
            onConfirm: function (options) {

              $.ajax({
                type: "POST",
                contentType: "application/json;charset=UTF-8",
                data: json_data,
                datatype: 'json',
                url: "/del_project",
                success: function (result) {

                  if (result['is_success']) {
                    location.reload();
                  } else {
                    $(".alert_bd").text(result['msg'])
                    $modal.modal();
                  }

                },
                error: function (e) {
                  console.log(e.status);
                  console.log(e.responseText);
                }
              });


            },
            // closeOnConfirm: false,
            onCancel: function () {
            }
          });

        }


        // 删除
        function del() {
          check_id = []

          $("#tbody").find('input:checkbox').each(function () { //遍历所有复选框
            if ($(this).prop('checked') == true) {
              check_id.push($(this).val())
            }

          });

          if (check_id.length == 0){
            $(".alert_bd").text('没有勾选删除的数据！')
            var $modal = $('#my-alert');
            $modal.modal();
            return
          }


          json_data = JSON.stringify({'del_list': check_id})
          ajax_del(json_data)


        }


        function del_single(id) {

          check_id = [id]
          json_data = JSON.stringify({'del_list': check_id})
          ajax_del(json_data)

        }


        //跳转页面
        function change_page() {
          var change_page = $("#page_select").val();

          find_page(change_page)

        }

        //上一页
        function back_page() {

          var change_page = $("#page_select").val();
          back_page_num = parseInt(change_page) - 1

          if (back_page_num >= 1){
            find_page(back_page_num)
            $("#page_select").val(back_page_num.toString())
          }

        }

        //下一页
        function next_page() {

          var change_page = $("#page_select").val();
          next_page_num = parseInt(change_page) + 1

          if (next_page_num <= page_num){
            find_page(next_page_num)
            $("#page_select").val(next_page_num.toString())
          }

        }








    </script>
  </body>

</html>